import React from 'react';
import Welcome from '../components/test.jsx'

class Clock extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            date : new Date(),
            num : 1
        }

    }

    tick() {
        this.setState({
            date : new Date()
        })
    }

    componentDidMount() {
        this.timer = setInterval(
        () => this.tick(), 
        1000)
    }
    
    componentWillUnmount() {
        clearInterval(this.timer);
    }
    
    handleClick() {
        this.setState({
            num : ++this.state.num
        })
    }
    render() {
        return (
            <div>
                <Welcome time={ this.state.date.toLocaleTimeString() } />
                <button type="button" onClick={this.handleClick.bind(this)}>{ this.state.num }</button>
            </div>
        )
    }
}

export default Clock;